//
//  MainPresenter.m
//  MVP
//
//  Created by 曹敬贺 on 16/8/4.
//  Copyright © 2016年 北京无限点乐科技有限公司. All rights reserved.
//

#import "MainPresenter.h"
#import "ItemTableViewCell.h"
#import "ItemData.h"

@interface MainPresenter ()
@property (nonatomic, strong) NSMutableArray * dataArray;
@end

@implementation MainPresenter



- (void)requestData
{
    for (int i = 0; i < 10; i++) {
        ItemData * item = [[ItemData alloc]init];
        item.user = self.user;
        item.itemName = [NSString stringWithFormat:@"SuperMan%d",i];
        item.itemDesc = [NSString stringWithFormat:@"这是MVP设计模式中Cell的第%d行",i];
        [self.dataArray addObject:item];
    }
    [self.delegate requestFinished];
}
#pragma mark - Lazy
- (NSMutableArray *)dataArray
{
    if (! _dataArray)
    {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}

#pragma mark - UITableView Delegate

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ider = @"ider";
    
    ItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ider];
    if (cell == nil) {
        cell =
        [[ItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ider];
    }
    
    ItemData * currentItem = [self.dataArray objectAtIndex:indexPath.row];
    [cell bandingData:currentItem];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80.0;
}


@end
